<template>
  <div>
    <!-- 政策模板 START -->
    <div class="haruyuki-scrollbar-70vh haruyuki-p-10">
      <div class="tree aisle-policy-bg" v-for="(dataItem, dataIndex) in data" :key="dataIndex">
        <details open>
          <summary class="summary-box">
            <div
              class="tree-item haruyuki-width-100 haruyuki-flex-space-between haruyuki-align-items-center"
            >
              <div class="haruyuki-flex1">
                <span class="haruyuki-size-16 policy-ml-3 policy-mr-3"
                  >通道名称：{{ dataItem.aisleName }}</span
                >
              </div>
              <!-- <div class="haruyuki-flex-center">
                <div class="haruyuki-mr-10">
                  <span>成本费率：</span>
                  <el-input-number
                    size="mini"
                    v-model="dataItem.aptRate"
                    :precision="4"
                    :step="0.0001"
                    :min="0"
                    :max="1"
                  ></el-input-number>
                  <span> %</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>分润比例：</span>
                  <el-input-number
                    size="mini"
                    v-model="dataItem.aptScale"
                    :precision="0"
                    :min="1"
                    :max="100"
                  ></el-input-number>
                  <span> %</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>封顶金额：</span>
                  <el-input-number
                    size="mini"
                    v-model="dataItem.aptMax"
                    :precision="2"
                    :step="0.1"
                    :min="0"
                  ></el-input-number>
                  <span> ¥</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>封底金额：</span>
                  <el-input-number
                    size="mini"
                    v-model="dataItem.aptMin"
                    :precision="2"
                    :step="0.1"
                    :min="0"
                  ></el-input-number>
                  <span> ¥</span>
                </div>
                <div class="policy-mr-3">
                  <el-button
                    type="primary"
                    size="mini"
                    plain
                    @click.stop="submitChildCover(dataItem)"
                    >一键填入</el-button
                  >
                </div>
              </div> -->
            </div>
          </summary>
          <details v-for="(item, index) in dataItem.levelList" :key="index" open>
            <summary class="haruyuki-flex haruyuki-align-items-center">
              <div class="tree-item haruyuki-flex-center">
                <span class="haruyuki-mr-20">阶梯{{ index + 1 }}</span>
                <div class="haruyuki-flex haruyuki-align-items-center">
                  范围区间：<el-input-number
                    size="mini"
                    v-model="item.aptStartMoney"
                    :precision="2"
                    :step="0.1"
                    :min="0"
                  ></el-input-number
                  ><span>~</span
                  ><el-input-number
                    size="mini"
                    v-model="item.aptEndMoney"
                    :precision="2"
                    :step="0.1"
                    :min="0.1"
                  ></el-input-number>
                  <div
                    class="policy-ml-3 policy-mr-3"
                    v-if="item.id == dataItem.stateIndex"
                  >
                    <el-button
                      type="text"
                      size="mini"
                      @click="() => ladderAppend(item, index, dataIndex)"
                    >
                      新增
                    </el-button>
                  </div>
                  <div
                    class="policy-ml-3"
                    v-if="item.id == dataItem.stateIndex && index != 0"
                  >
                    <el-button
                      type="text"
                      size="mini"
                      @click="() => ladderRemove(index, dataIndex)"
                    >
                      删除
                    </el-button>
                  </div>
                </div>
              </div>
            </summary>
            <!-- 扫码 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.scanRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.scanRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ cItem.compName }}</span>
                </summary>
                <div v-if="cItem.payType == 3">
                  <details open>
                    <summary>
                      <span class="tree-item">银联二维码小额（小于等于1000）</span>
                    </summary>
                    <details v-for="(uItem, uIndex) in ysfRateList(cItem.unionRate, 1)" :key="uIndex" open>
                      <summary>
                        <span class="tree-item">{{ cItem.compName }}{{ ysfRateTypeName(uItem.ylType) }}</span>
                      </summary>
                      <details>
                        <summary>
                          <div class="tree-item input-tree-item">
                            <span class="input-tree-item-left">{{ cItem.compName }}成本费率：()%</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.rate"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                          </div>
                          <div class="tree-item input-tree-item">
                            <span class="input-tree-item-left">{{ cItem.compName }}分润比例：()%</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.scale"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                          </div>
                          <div class="tree-item input-tree-item" v-if="uItem.ylType == 2 || uItem.ylType == 4">
                            <span class="input-tree-item-left">{{ cItem.compName }}封顶金额：x元</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMax"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                          </div>
                          <div class="tree-item input-tree-item">
                            <span class="input-tree-item-left">{{ cItem.compName }}封底金额：x元</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMin"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                          </div>
                        </summary>
                      </details>
                    </details>
                  </details>
                  <details open>
                    <summary>
                      <span class="tree-item">银联二维码大额（大于等于1000）</span>
                    </summary>
                    <details v-for="(uItem, uIndex) in ysfRateList(cItem.unionRate, 2)" :key="uIndex" open>
                      <summary>
                        <span class="tree-item">{{ cItem.compName }}{{ ysfRateTypeName(uItem.ylType) }}</span>
                      </summary>
                      <details>
                        <summary>
                          <div class="tree-item input-tree-item">
                            <span class="input-tree-item-left">{{ cItem.compName }}成本费率：()%</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.rate"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                          </div>
                          <div class="tree-item input-tree-item">
                            <span class="input-tree-item-left">{{ cItem.compName }}分润比例：()%</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.scale"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                          </div>
                          <div class="tree-item input-tree-item" v-if="uItem.ylType == 2 || uItem.ylType == 4">
                            <span class="input-tree-item-left">{{ cItem.compName }}封顶金额：x元</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMax"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                          </div>
                          <div class="tree-item input-tree-item">
                            <span class="input-tree-item-left">{{ cItem.compName }}封底金额：x元</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMin"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                          </div>
                        </summary>
                      </details>
                    </details>
                  </details>
                </div>
                <div v-else>
                  <details open>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}成本费率：()%</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}分润比例：()%</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}封顶金额：x元</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}封底金额：x元</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                    </summary>
                  </details>
                </div>
              </details>
            </details>
            <!-- 扫码 END -->
            
            <!-- 刷卡 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.posRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.posRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ posRateTypeName(cItem.payType) }}</span>
                </summary>
                <!-- payType  刷卡 1.贷记卡 2.借记卡 -->
                <details>
                  <summary>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">成本费率：()%</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">分润比例：()%</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.scale"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                    <div class="tree-item input-tree-item" v-if="cItem.payType == 2">
                      <span class="input-tree-item-left">封顶金额：x元</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMax"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">封底金额：x元</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMin"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                  </summary>
                </details>
              </details>
            </details>
            <!-- 刷卡 END -->
            <!-- 云闪付 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.ysfRate.typeName }}</span>
              </summary>
              <details open>
                <summary>
                  <span class="tree-item">云闪付优惠（小于等于1000）</span>
                </summary>
                <details v-for="(cItem, cIndex) in ysfRateList(item.typeVO.ysfRate.rateList, 1)" :key="cIndex" open>
                  <summary>
                    <span class="tree-item">{{ ysfRateTypeName(cItem.ylType) }}</span>
                  </summary>
                  <details>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}成本费率：()%</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}分润比例：()%</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 4">
                        <span class="input-tree-item-left">{{ cItem.compName }}封顶金额：x元</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}封底金额：x元</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                    </summary>
                  </details>
                </details>
              </details>
              <details open>
                <summary>
                  <span class="tree-item">云闪付（大于等于1000）</span>
                </summary>
                <details v-for="(cItem, cIndex) in ysfRateList(item.typeVO.ysfRate.rateList, 2)" :key="cIndex" open>
                  <summary>
                    <span class="tree-item">{{ ysfRateTypeName(cItem.ylType) }}</span>
                  </summary>
                  <details>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}成本费率：()%</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}分润比例：()%</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 4">
                        <span class="input-tree-item-left">{{ cItem.compName }}封顶金额：x元</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}封底金额：x元</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                      </div>
                    </summary>
                  </details>
                </details>
              </details>
            </details>
            <!-- 云闪付 END -->
            <!-- 快捷 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.quickRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.quickRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">快捷支付</span>
                </summary>
                <details>
                  <summary>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">成本费率：()%</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">分润比例：()%</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.scale"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                  </summary>
                </details>
              </details>
            </details>
            <!-- 快捷 END -->
            <!-- 垫资 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.codeAdvanceRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.codeAdvanceRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ codeAdvanceRateTypeName(cItem.ylType) }}</span>
                </summary>
                <details>
                  <summary>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">成本费率：()%</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                    <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 3">
                      <span class="input-tree-item-left">封顶金额：x元</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMax"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">封底金额：x元</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMin"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                    </div>
                  </summary>
                </details>
              </details>
            </details>
            <!-- 垫资 END -->
          </details>
        </details>
      </div>
    </div>
    <!-- 政策模板 END -->
  </div>
</template>

<script>
import {
  templatePolicyList,
  templatePolicyDetail,
  getPolicyDetail,
} from "@/api/system/tenant";
let intId = 1;
let pid = 1000;
export default {
  props: {
    policyForm: Object,
    oem: Object,
    aisleCode: {
      type: [Number, String],
      default: "",
    },
  },
  data() {
    return {
      policyRules: {
        polName: [
          { required: true, message: "请输入政策名称", trigger: "blur" },
        ],
        polType: [
          { required: true, message: "请选择政策类型", trigger: "blur" },
        ],
        polCategory: [
          { required: true, message: "请选择政策类别", trigger: "blur" },
        ],
        polKind: [
          { required: true, message: "请选择政策分类", trigger: "blur" },
        ],
      },
      policyTemplate: [], // 一键全入 模板集合
      policyTemplateCode: "", //一键全入 编号
      data: [], //通道政策 树形数据
      aptTemplate: {
        aptRate: 0,
        aptScale: 0,
        aptMax: 0,
        aptMin: 0,
      },
    };
  },
  computed: {
    /* 垫资 ylType 1.扫码垫资 2.贷记卡垫资 3.借记卡垫资 */
    codeAdvanceRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '扫码垫资');
        } else if (val == 2) {
          return (val = '贷记卡垫资');
        } else if (val == 3) {
          return (val = '借记卡垫资');
        }
      };
    },
    /* 刷卡 payType 1.贷记卡 2.借记卡 */
    posRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '贷记卡');
        } else if (val == 2) {
          return (val = '借记卡');
        }
      };
    },
    /* 云闪付 ylType 1.贷记卡小额 2.借记卡小额 3.贷记卡大额 4.借记卡大额 */
    ysfRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '贷记卡小额');
        } else if (val == 2) {
          return (val = '借记卡小额');
        } else if (val == 3) {
          return (val = '贷记卡大额');
        } else if (val == 4) {
          return (val = '借记卡大额');
        }
      };
    },
    /* 云闪付 大小额分层 */
    ysfRateList() {
      return (unionRate, type) => {
        if (type == 1) {
          return unionRate.filter(item => item.ylType == 1 || item.ylType == 2)
        } else if (type == 2) {
          return unionRate.filter(item => item.ylType == 3 || item.ylType == 4)
        }
      };
    }
  },
  watch: {},
  created() {
    this.data = [];
    this.getTemplatePolicyList();
    this.getPolicyDetails();
  },
  methods: {
    /* 政策通用模板查询 */
    async getTemplatePolicyList() {
      await templatePolicyList().then((tempRes) => {
        this.policyTemplate = tempRes.data.data.records;
      });
    },
    /* 政策详情 */
    async getPolicyDetails() {
      await getPolicyDetail(
        this.oem.tenantId,
        this.oem.userNo,
        this.oem.userType,
        this.aisleCode ? this.aisleCode : ""
      ).then(async (res) => {
        if (res.data.code == "200") {
          let datas = res.data.data;
          for (let i = 0; i < datas.length; i++) {
            this.$set(datas[i], "aptRate", 0);
            this.$set(datas[i], "aptScale", 0);
            this.$set(datas[i], "aptMax", 0);
            this.$set(datas[i], "aptMin", 0);

            // await this.templatePolicy(datas[i]);
            for (let j = 0; j < datas[i].levelList.length; j++) {
              this.$set(datas[i].levelList[j], "id", intId++);
            }
          }

          this.$nextTick(() => {
            this.data = JSON.parse(JSON.stringify(datas));
          });
        } else {
          this.$message({
            type: "error",
            message: res.data.message,
          });
        }
      });
    },
    /* 匹配政策通道编号 单模板查询 赋值 */
    async templatePolicy(data) {
      await templatePolicyList(data.aisleCode).then((tempRes) => {
        this.$set(data, "template", tempRes.data.data.records);
        return data;
      });
    },
    /* 通道政策模板 根据已有通道全渲染 */
    async templateAllChange(e) {
      await templatePolicyDetail(
        e,
        this.oem.tenantId,
        this.oem.userNo,
        this.oem.userType
      ).then((res) => {
        let templateData = res.data.data;

        for (let t = 0; t < templateData.policyList.length; t++) {
          for (let i = 0; i < this.data.length; i++) {
            if (templateData.policyList[t].aisleCode == this.data[i].aisleCode) {
              this.data[i].levelList = templateData.policyList[t].levelList;
              for (let j = 0; j < this.data[i].levelList.length; j++) {
                this.$set(this.data[i].levelList[j], "id", intId++);
              }
            }
          }
        }

      });
    },
    /* 通道政策模板 根据单通道选择模板单渲染 */
    async templateChildChange(e, index) {
      await templatePolicyDetail(
        e,
        this.oem.tenantId,
        this.oem.userNo,
        this.oem.userType
      ).then((res) => {

        /* this.initData = data.policyList;
        for (let i = 0; i < this.initData.length; i++) {
          this.$set(this.initData[i], "aptRate", 0);
          this.$set(this.initData[i], "aptScale", 0);
          this.$set(this.initData[i], "aptMax", 0);
          this.$set(this.initData[i], "aptMin", 0);
          for (let j = 0; j < this.initData[i].levelList.length; j++) {
            this.$set(this.initData[i].levelList[j], "id", intId++);
          }
        }
        this.$nextTick(() => {
          this.data = JSON.parse(JSON.stringify(this.initData));
        }); */

        let templateData = res.data.data;
        for (let t = 0; t < templateData.aisleList.length; t++) {
          if (
            templateData.aisleList[t].aisleCode == this.data[index].aisleCode
          ) {
            this.$set(this.data[index], "templatePolNo", templateData.polNo);
            this.data[index].intervalList =
              templateData.aisleList[t].intervalList;
            for (let j = 0; j < this.data[index].intervalList.length; j++) {
              this.$set(this.data[index].intervalList[j], "isShow", true);
              this.$set(this.data[index].intervalList[j], "id", intId++);
              this.$set(this.data[index].intervalList[j].posTrad, "isShow", true);
              for (
                let k = 0;
                k < this.data[index].intervalList[j].productList.length;
                k++
              ) {
                this.$set(
                  this.data[index].intervalList[j].productList[k],
                  "isShow",
                  true
                );
                this.$set(
                  this.data[index].intervalList[j].productList[k],
                  "id",
                  pid++
                );
              }
            }
          }
        }
      });
    },
    /* 全通道政策模板 一键填入 */
    submitCover() {
      if (this.aptTemplate.aptRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入成本费率",
        });
      } else if (this.aptTemplate.aptScale == 0) {
        this.$message({
          type: "warning",
          message: "请输入结算比例",
        });
      } else if (this.aptTemplate.aptMax == 0) {
        this.$message({
          type: "warning",
          message: "请输入封顶金额",
        });
      } else if (this.aptTemplate.aptMin == 0) {
        this.$message({
          type: "warning",
          message: "请输入最低金额",
        });
      } else {
        for (let d = 0; d < this.data.length; d++) {
          for (let i = 0; i < this.data[d].levelList.length; i++) {
            for (const codeAdvanceRate of this.data[d].levelList[i].typeVO.codeAdvanceRate.rateList) {
              codeAdvanceRate.rate = this.aptTemplate.aptRate;
              codeAdvanceRate.scale = this.aptTemplate.aptScale;
              codeAdvanceRate.aptMax = this.aptTemplate.aptMax;
              codeAdvanceRate.aptMin = this.aptTemplate.aptMin;
            }

            for (const posRate of this.data[d].levelList[i].typeVO.posRate.rateList) {
              posRate.rate = this.aptTemplate.aptRate;
              posRate.scale = this.aptTemplate.aptScale;
              posRate.aptMax = this.aptTemplate.aptMax;
              posRate.aptMin = this.aptTemplate.aptMin;
            }

            for (const quickRate of this.data[d].levelList[i].typeVO.quickRate.rateList) {
              quickRate.rate = this.aptTemplate.aptRate;
              quickRate.scale = this.aptTemplate.aptScale;
              quickRate.aptMax = this.aptTemplate.aptMax;
              quickRate.aptMin = this.aptTemplate.aptMin;
            }

            for (const scanRate of this.data[d].levelList[i].typeVO.scanRate.rateList) {
              if (scanRate.payType == 3) {
                for (const scanRateItem of scanRate.unionRate) {
                  scanRateItem.rate = this.aptTemplate.aptRate;
                  scanRateItem.scale = this.aptTemplate.aptScale;
                  scanRateItem.aptMax = this.aptTemplate.aptMax;
                  scanRateItem.aptMin = this.aptTemplate.aptMin;
                }
              } else {
                scanRate.rate = this.aptTemplate.aptRate;
                scanRate.scale = this.aptTemplate.aptScale;
                scanRate.aptMax = this.aptTemplate.aptMax;
                scanRate.aptMin = this.aptTemplate.aptMin;
              }
            }

            for (const ysfRate of this.data[d].levelList[i].typeVO.ysfRate.rateList) {
              ysfRate.rate = this.aptTemplate.aptRate;
              ysfRate.scale = this.aptTemplate.aptScale;
              ysfRate.aptMax = this.aptTemplate.aptMax;
              ysfRate.aptMin = this.aptTemplate.aptMin;
            }
          }
        }
        
      }
    },
    /* 单通道政策模板 一键填入 */
    submitChildCover(data) {
      if (data.aptRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入成本费率",
        });
      } else if (data.aptScale == 0) {
        this.$message({
          type: "warning",
          message: "请输入分润比例",
        });
      } else if (data.aptMax == 0) {
        this.$message({
          type: "warning",
          message: "请输入封顶金额",
        });
      } else if (data.aptMin == 0) {
        this.$message({
          type: "warning",
          message: "请输入封低金额",
        });
      } else {
        for (let i = 0; i < data.levelList.length; i++) {
          for (const codeAdvanceRate of data.levelList[i].typeVO.codeAdvanceRate.rateList) {
            codeAdvanceRate.rate = data.aptRate;
            codeAdvanceRate.scale = data.aptScale;
            codeAdvanceRate.aptMax = data.aptMax;
            codeAdvanceRate.aptMin = data.aptMin;
          }

          for (const posRate of data.levelList[i].typeVO.posRate.rateList) {
            posRate.rate = data.aptRate;
            posRate.scale = data.aptScale;
            posRate.aptMax = data.aptMax;
            posRate.aptMin = data.aptMin;
          }

          for (const quickRate of data.levelList[i].typeVO.quickRate.rateList) {
            quickRate.rate = data.aptRate;
            quickRate.scale = data.aptScale;
            quickRate.aptMax = data.aptMax;
            quickRate.aptMin = data.aptMin;
          }

          for (const scanRate of data.levelList[i].typeVO.scanRate.rateList) {
            if (scanRate.payType == 3) {
              for (const scanRateItem of scanRate.unionRate) {
                scanRateItem.rate = data.aptRate;
                scanRateItem.scale = data.aptScale;
                scanRateItem.aptMax = data.aptMax;
                scanRateItem.aptMin = data.aptMin;
              }
            } else {
              scanRate.rate = data.aptRate;
              scanRate.scale = data.aptScale;
              scanRate.aptMax = data.aptMax;
              scanRate.aptMin = data.aptMin;
            }
          }

          for (const ysfRate of data.levelList[i].typeVO.ysfRate.rateList) {
            ysfRate.rate = data.aptRate;
            ysfRate.scale = data.aptScale;
            ysfRate.aptMax = data.aptMax;
            ysfRate.aptMin = data.aptMin;
          }
        }
      }
    },
    /* 新增阶梯 */
    ladderAppend(data, index, dataIndex) {
      let intData = JSON.parse(JSON.stringify(data));
      intData.id = intId++;
      intData.aptStartMoney = intData.aptEndMoney;
      intData.aptEndMoney = intData.aptEndMoney + 1;
      intData.aptGrade = intData.id; //阶段层级赋值

      this.data[dataIndex].levelList.push(intData);
    },
    /* 删除阶梯 */
    ladderRemove(index, dataIndex) {
      this.data[dataIndex].levelList.splice(index, 1);
    },
  },
};
</script>

<style lang="scss" scoped>
.aisle-template {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
}
details {
  padding-left: 20px;
}

details summary:focus {
  outline: none;
}

summary {
  width: 100%;
  /* border-bottom: 1px solid #e0eafc; */
  border-bottom: 1px solid #ffffff;
}

summary::-webkit-details-marker {
  display: none;
}
summary:not(:only-child):before {
  content: "\e791";
  color: #606266;
  transition: color 0.15s linear;
  font-size: 16px;
  cursor: pointer;
  margin-right: 6px;
  font-family: element-icons !important;
}
details[open] > summary:not(:only-child):before {
  content: "\e790";
  color: #606266;
  transition: color 0.15s linear;
  font-size: 16px;
  cursor: pointer;
  margin-right: 6px;
  font-family: element-icons !important;
}

.tree {
  /* background: linear-gradient(90deg, #8e9eab 0%, #eef2f3 100%); */
  margin-bottom: 30px;
}
/* Haruyuki row height line */
.tree-item {
  height: 40px;
  line-height: 40px;
  transition: all 1s ease 0s;
  user-select: none;
  -moz-user-select: none; /*火狐*/
  -webkit-user-select: none; /*webkit浏览器*/
  -ms-user-select: none; /*IE10*/
  -khtml-user-select: none; /*早期浏览器*/
}
.tree-item:hover {
  background: rgba(195,207,226, 0.2);
  border-radius: 6px;
}

.aisle-policy-bg {
  /* background-color: #e0eafc; */
  background-color: #f9fafc;
  /* padding: 6px 0; */
  padding-left: -10px;
  padding-right: 10px;
  border-radius: 6px;
  /* box-shadow: 0 2px 12px rgba(224, 234, 252, 0.8); */
  box-shadow: 0 2px 12px rgba(153,167,177, 0.4);
  color: #111111;
}

.summary-box {
  display: flex;
  align-items: center;
  padding: 6px 0;
}

.input-tree-item {
  display: flex;
  align-items: center;
}

.input-tree-item-left {
  width: 300px;
}
.policy-mr-3 {
  margin-right: 3px;
}
.policy-ml-3 {
  margin-left: 3px;
}
</style>
